if(length(grep("smoke$", getwd())) ) {

source("CohortDeffFunction.r")
} else {

source("C:/Users/hjiang/Desktop/sampleSizeGoogle/smoke/CohortDeffFunction.r")

        }

#source("CohortDeffFunction.r")

library(mgcv)
library(MASS)
library(INLA)
library(lme4)
library(glmmBUGS)
library(nlme)
library(gee)
parameters=list(
   size=500,
   DiffEffSizeGroup = 0.75              ,
   DiffEffSizeIndi = 2                   ,
   DiffEffSizeInter = 1.2                 ,
   GroupMissRate = 0.10                     ,
   IndiMissRate = 0.05                       ,
   SmokeMissRate = 0.05                       ,
   probIndiVar = 0.1                           ,
   probGrVar = 0.4                       ,
   regionsd = 0.5    ,
   mu = 4/6
)
Ngroups = c(10, 20, 50, 100)
simulationTime=500

nullmodel=T
varying=NULL
Nmethods = c("inla")
inlanull500 = allEstCI(Ngroups,parameters, varying=NULL,nullmodel,simulationTime, Nmethods )
save(inlanull500, file="inlanull500.Rdata")


nullmodel = T
varying = list("mu"=1/9)
Nmethods = c("inla")
null500lowpre = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime, Nmethods)
save(null500lowpre, file="inlanull500lowpre.Rdata")

####### when low prevalence and low correlation#######
nullmodel = T
varying = list("mu"=1/9, "regionsd"=0.1)
Nmethods = c("inla")
null500lowprelowcor = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime, Nmethods)
save(null500lowprelowcor, file="inlanull500lowprelowcor.Rdata")

###### when size=5000 ###########
nullmodel= T
varying = list("size"=5000)

null5000 = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime, Nmethods)
save(null5000, file="inlanull5000.Rdata")

####### low prevelence ###########
nullmodel = T
varying = list("size"=5000, "mu"=1/9)
null5000lowpre = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime, Nmethods)
save(null5000lowpre, file="inlanull5000lowpre.Rdata")

####### when low prevalence and low correlation#######
nullmodel = T
varying = list("size"=5000, "mu"=1/9, "regionsd"=0.2)
null5000lowprelowcor = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime, Nmethods)
save(null5000lowprelowcor, file="inlanull5000lowprelowcor.Rdata")




##############################
###### Second Senario #########
###############################
###### effect size = 0 null model #######
nullmodel = F
varying=NULL
s500 = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime,Nmethods)

save(s500, file="inlas500.Rdata")

####### when low prevalence #######
nullmodel = F
varying = list("mu"=1/9)
s500lowpre = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime)
save(s500lowpre, file="inlas500lowpre.Rdata")

####### when low prevalence and low correlation#######
nullmodel = F
varying = list("mu"=1/9, "regionsd"=0.2)
Nmethods = c("inla")
s500lowprelowcor = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime, Nmethods)
save(s500lowprelowcor, file="inlas500lowprelowcor.Rdata")



###### when size=5000 ###########
nullmodel= F
varying = list("size"=5000)
s5000 = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime)
save(s5000, file="inlas5000.Rdata")


nullmodel = F
varying = list("size"=5000, "mu"=1/9)
s5000lowpre = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime)
save(s5000lowpre, file="inlas5000lowpre.Rdata")


####### when low prevalence and low correlation#######
nullmodel = F
varying = list("size"=5000, "mu"=1/9, "regionsd"=0.2)
s5000lowprelowcor = allEstCI(Ngroups,parameters, varying,nullmodel,simulationTime)
save(s5000lowprelowcor, file="inlas5000lowprelowcor.Rdata")
